﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace=" System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="TarreOA.TarreOAModels" %>
<%@ Import Namespace="TarreOA.TarreOABLL" %>

<script runat="server">

    private string curP;
    private string catalogName;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Response.Redirect("~/Login.aspx");
        }
        else if (!Page.IsPostBack)
        {
            if (Request["c_P"] != null && Request["c_N"] != null && Request.QueryString.Get("c_id") != null)
            {
                catalogName = Request["c_N"]; 
                this.curP = Request["c_P"];
                this.btnBack.Attributes.Add("c_id", Request.QueryString.Get("c_id"));
            }   
            this.findAllPath();
            ViewState["catalogName"] = catalogName; 
        }   
    }

    protected void findAllPath()
    {
        this.DdlTarget.Items.Clear();
        NetDiskCatalogFolderAndFileService ndcfafService = new NetDiskCatalogFolderAndFileService();
        List<string> list = ndcfafService.findCurrentCatalogAllFolder(FindConfigurationPath.instance().NetDiskRoots[catalogName].ToString());
        ListItem rootItem = new ListItem("\\", "");
        this.DdlTarget.Items.Add(rootItem); 
        if (list != null)
        {
            foreach (string pathAndName in list)
            {
                string[] pan = pathAndName.Split(',');
                ListItem listItem = new ListItem(pan[1], pan[0].Replace(FindConfigurationPath.instance().NetDiskRoots[catalogName].ToString(), ""));
                if (this.curP != null && this.curP.Equals(listItem.Value))
                {
                    listItem.Selected = true;
                }
                this.DdlTarget.Items.Add(listItem);
            }
        }
    }

    string ts;
    protected void btnSubmit_ServerClick(object sender, EventArgs e)
    {
        if (ViewState["catalogName"] != null)
        {
            catalogName = (string)ViewState["catalogName"]; 
        }  
        string target = Request.Params.GetValues(this.DdlTarget.ClientID)[0];
        this.ts = FindConfigurationPath.instance().NetDiskRoots[catalogName].ToString() + target;
        //Thread t = new Thread(new ThreadStart(UploadFile));
        //t.Start();

        //判断路径是否存在，如果不存在则创建
        if (!Directory.Exists(ts))
            Directory.CreateDirectory(ts);
        
        UploadFile(); 
        ViewState["catalogName"] = catalogName; 
    }

    private void UploadFile()
    {
        long size = FileUpload1.FileContent.Length; 
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(ts + "\\" + FileUpload1.FileName); 
        }
        if (FileUpload2.HasFile)
        {
            FileUpload2.SaveAs(ts + "\\" + FileUpload2.FileName); 
        }
        if (FileUpload3.HasFile)
        {
            FileUpload3.SaveAs(ts + "\\" + FileUpload3.FileName); 
        }   
    }

    protected void btnBack_ServerClick(object sender, EventArgs e)
    {
        if (ViewState["catalogName"] != null)
        {
            catalogName = (string)ViewState["catalogName"];
        }
        string c_id = ((HtmlInputButton)sender).Attributes["c_id"];
        Response.Redirect("NetDiskCatalogFolderShow.aspx?C_N=" + catalogName + "&C_ID=" + c_id); 
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript" src="../js/NetDisk.js"></script>

                        <link rel="Stylesheet" type="text/css" href="../Styles/right_style.css" />
                <script type="text/javascript" src="../Scripts/jquery.ui/js/jquery.js"></script>

                <style type="text/css">
                <!--
                html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
                scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
                -->
                </style>

</head>
<body>
    <form id="form1" runat="server">
    <div class="sub_right_top">
  <div class="hdm_header" >
    <div class="tb1_on"><h2 class="h2_icon">网络硬盘</h2></div>

    <div class="clear"></div>
  </div>
  <div class="hdm_footer">
    <div style="height:13px; overflow:hidden;"></div>
            <table width="97%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#77acd0" style="border-collapse:collapse;">
                <tr bgcolor="#b1d5ef">
                    <td colspan="2" nowrap="nowrap">
                        &nbsp;&nbsp;<img align="absMiddle" border="0" src="../images/upload.gif">&nbsp;<font style="font-size:12px">上传文件</font></td>
                </tr>
                <tr>
                    <td align="right" nowrap="nowrap">
                        <font style="font-size: 12px">上传到此位置：</font></td>
                    <td nowrap="nowrap">
                        <asp:DropDownList ID="DdlTarget" runat="server" Width="223px">
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td align="right" nowrap="nowrap" style="height: 74px">
                        <font style="font-size: 12px">文件：</font></td>
                    <td nowrap="nowrap" style="height: 74px">
                        <asp:FileUpload ID="FileUpload1" runat="server" /><br>
                        <asp:FileUpload ID="FileUpload2" runat="server" /><br>
                        <asp:FileUpload ID="FileUpload3" runat="server" /></td>
                </tr>
                <tr id="uploading" style=" display:none">
                    <td align="center" colspan="2" nowrap="nowrap">
                        <font style="font-size: 12px"><asp:Label ID="Label1" runat="server" Text="正在添加文件到您的个人文件柜中，请稍候……"></asp:Label><br />
                            </font> 
                        <asp:Panel ID="Panel1" runat="server" Height="16px" Width="260px" BorderStyle="Double" BackColor="#FFFFC0">
                        <marquee class="loading" direction="right" scrollamount="5" scrolldelay="10">
                            <table style="" cellpadding="2" >
                                <tr>
                                    <td style="width: 6px; height: 12px" bgcolor="#99cccc">
                                    </td>
                                    <td style="width: 6px; height: 12px" bgcolor="#99cccc">
                                    </td>
                                    <td style="width: 6px; height: 12px" bgcolor="#99cccc">
                                    </td>
                                    <td style="width: 6px; height: 12px" bgcolor="#99cccc">
                                    </td>
                                    <td style="width: 6px; height: 12px" bgcolor="#99cccc">
                                    </td>
                                    <td style="width: 6px; height: 12px" bgcolor="#99cccc">
                                    </td>
                                    <td bgcolor="#99cccc" style="width: 6px; height: 12px">
                                    </td>
                                    <td bgcolor="#99cccc" style="width: 6px; height: 12px">
                                    </td>
                                </tr>
                            </table>
                        </marquee>
                        </asp:Panel>
                    </td>
                </tr>
                <tr id="toUpload" bgcolor="#b1d5ef">
                    <td align="center"  colspan="2" nowrap="nowrap"
                        style="height: 30px">
                        <input id="btnSubmit" runat="server" class="BigButton" name="btnSubmit" onclick="return uploadFile()"
                            onserverclick="btnSubmit_ServerClick" type="submit" value="确定" />&nbsp;&nbsp;
                        <input id="btnBack" name="btnBack" type="button" value="" class="fanhui_anniu"  runat="server" onserverclick="btnBack_ServerClick" /></td>
                </tr>
            </table>
    </div>
    </div>
    </form>
</body>
</html>
